package demo2;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

@FunctionalInterface
interface Opp {
    void test();
}

class Eg implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        //构建大堆
        return o2.compareTo(o1);
    }
}

public class TestLast {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "lambda");

        /*map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key: " + integer + " val: " + s);
            }
        });*/
        map.forEach((a, s) -> System.out.println("key: " + a + " val: " + s));
        System.out.println();
    }
    public static void main5(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("bit");
        list.add("lambda");
        /*list.forEach(new Consumer<String>() {
            //还是匿名内部类
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/
        list.forEach((s) -> System.out.println(s));
    }
    public static void main4(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(
                (o1,o2) -> {return o2.compareTo(o1);}
        );
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        System.out.println(queue.peek());
    }
    public static void main11(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            //匿名内部类实现大堆
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2.compareTo(o1);
            }
        });

        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        System.out.println(queue.peek());
    }
    public static void main2(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Eg());
        //此时我们自己构建比较器
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        System.out.println(queue.peek());
    }

    public static void main1(String[] args) {
        int sz = 100;
        Opp opp = () -> {
            System.out.println("调用" + sz);
        };
    }
}
